﻿using System.Collections.Generic;
using System.Linq;
using Irony.Parsing;

namespace DynamicGeometry
{
    public class CompileError
    {
        public static List<CompileError> GetCompilerErrors(SyntaxErrorList syntaxErrors)
        {
            if (syntaxErrors.IsEmpty())
            {
                return null;
            }

            return syntaxErrors.Select(e => new CompileError()
            {
                Text = TranslateMessage(e)
            }).ToList();
        }

        static string TranslateMessage(SyntaxError e)
        {
            var result = e.Message;
            if (result == "Unexpected end of file.")
            {
                result = "Unfinished expression";
            }
            return result;
        }

        public string Text { get; set; }
    }
}
